package com.alks.entity.data.enums.factoryquery;

import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Getter
public enum PcProcessEnum {
    PROCESS_CUT("冲裁","01"),
    PROCESS_HF("高频","02"),
    PROCESS_SP("配套","03"),
    PROCESS_SW("针车","04"),
    PROCESS_LAST("成型","05");

    private String processName;
    private String processCode;

    PcProcessEnum(String processName, String processCode) {
        this.processName=processName;
        this.processCode=processCode;
    }

    public static Map<String, String> toMap() {
        Map<String, String> map = new HashMap<>();
        for (PcProcessEnum process : PcProcessEnum.values()) {
            map.put(process.getProcessName(), process.getProcessCode());
        }
        return map;
    }

    public static Map<String, String>[] toMapArray() {
        int i=0;
        Map<String, String> map[] = new HashMap[PcProcessEnum.values().length];
        for (int j = 0; j < map.length; j++) {
            map[j] = new HashMap<>();
        }
        for (PcProcessEnum process : PcProcessEnum.values()) {
            map[i].put("name", process.getProcessName());
            map[i].put("code", process.getProcessCode());
            i++;
        }
        return map;
    }

    public static List<String> getNameList(){
        return Arrays.stream(PcProcessEnum.values()).map(PcProcessEnum::getProcessName).collect(Collectors.toList());
    }

    /**
     * 根据工艺名找工艺ID
     * @param processName
     * @return
     */
    public static String getCodeByName(String processName){
        return toMap().get(processName);
    }

    /**
     * 判断给定的processCode是否存在于枚举中
     * @param processCode 要检查的processCode
     * @return 如果processCode存在则返回true，否则返回false
     */
    public static boolean isProcessCodeExist(String processCode) {
        for (PcProcessEnum lsTypeEnum : values()) {
            if (lsTypeEnum.getProcessCode().equals(processCode)) {
                return true;
            }
        }
        return false;
    }
}
